package ru.jexp.rcp.supply.n;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.TreeDragSourceEffect;

import ru.jexp.rcp.supply.beans.ek.JExpTreeViewerNEk;
import ru.jexp.rcp.supply.beans.project.dvs.sostavizdelia.TreePathMerge;

public class EkTreeViewerDrag extends TreeDragSourceEffect
{
	private final JExpTreeViewerNEk tree;

	public EkTreeViewerDrag(JExpTreeViewerNEk tree)
	{
		super(tree.getTree());
		this.tree = tree;
	}

	@Override
	public void dragSetData(DragSourceEvent event)
	{
		IStructuredSelection selection = (IStructuredSelection) tree.getSelection();
		TreePathMerge path = (TreePathMerge) selection.getFirstElement();

		if (path != null && path.getValue() != null)
		{
			event.doit = false;
			return;
		}

		if (!TextTransfer.getInstance().isSupportedType(event.dataType))
		{
			event.doit = false;
			return;
		}

		event.data = "tranfer data";
	}
}
